package cate.common.table.dynins;


import cate.common.annotation.SplitParse;
import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import cate.common.table.d.GDHero;
import cate.common.util.SplitParser;
import easy.java.dev.note.NoteClass;

import java.util.ArrayList;
import java.util.List;

@NoteClass("徽章映射")
public class DynRuneRow extends ERow {

    private String j1Str;
    private String j2Str;
    private String j3Str;
    private String j4Str;

    @Override
    public void parse(XSSFRowWrap xrw) {
        super.parse(xrw);
        this.id = xrw.getInteger("强度等级", -1);
        this.j1Str = xrw.getString("战士");
        this.j2Str = xrw.getString("法师");
        this.j3Str = xrw.getString("坦克");
        this.j4Str = xrw.getString("辅助");
    }

    private List<Config> j1;
    private List<Config>  j2;
    private List<Config>  j3;
    private List<Config>  j4;

    @Override
    public void decode() {
        j1 = parseConfig(j1Str);
        j2 = parseConfig(j2Str);
        j3 = parseConfig(j3Str);
        j4 = parseConfig(j4Str);
    }

    private List<Config> parseConfig(String str) {
        List<Config> configs = SplitParser.parse(Config.class, str);
        if (configs != null) {
            configs.forEach(Config::decode);
        }
        return configs;
    }

    public List<Config> getConfigs(byte job) {
        switch (job) {
            case GDHero.Job.J1:
                return j1;
            case GDHero.Job.J2:
                return j2;
            case GDHero.Job.J3:
                return j3;
            case GDHero.Job.J4:
                return j4;
            default:
                return null;
        }
    }

    // 属性1：属性2：属性3：技能1：技能2
    public static class Config {
        @SplitParse(order = 0, defaultValue = "0", note = "属性1")
        public int attr1;
        @SplitParse(order = 1, defaultValue = "0", note = "属性2")
        public int attr2;
        @SplitParse(order = 2, defaultValue = "0", note = "属性3")
        public int attr3;
        @SplitParse(order = 3, defaultValue = "0", note = "技能1")
        public int skill1;
        @SplitParse(order = 4, defaultValue = "0", note = "技能2")
        public int skill2;


        public List<Integer> attrs = new ArrayList<>();

        public List<Integer> skills = new ArrayList<>();

        public void decode() {
            if (attr1 > 0) {
                attrs.add(attr1);
            }
            if (attr2 > 0) {
                attrs.add(attr2);
            }
            if (attr3 > 0) {
                attrs.add(attr3);
            }
            if (skill1 > 0) {
                skills.add(skill1);
            }
            if (skill2 > 0) {
                skills.add(skill2);
            }
        }
    }
}
